import { SET_NAV_LIST } from '../actionType'

// ts类型
export interface routeItem {
  name: string
  path: string
  query: string
  icon?: JSX.Element
  title?: string
  tags?: Array<string>
  images?: Array<string>
  describe?: string
}
interface IState {
  navList: Array<routeItem>
}
interface IAction {
  type: symbol;
  navList: Array<routeItem>
}

// 默认仓库数据
const defaultState = {
  navList: []
}

const reducer = (state: IState = defaultState, action: IAction) => {
  // reducer 不允许直接修改 state的数据
  const newState = { ...state }
  switch (action.type) {
    case SET_NAV_LIST:
      newState.navList = action.navList
      break
    default:
      console.log('navList没有发现type', action.type)
      return state
  }
  return newState
}

export default reducer
